home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok22.lha
/
Lists
/
TestLists.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
4KB
|
172 lines
(**********************************************************************
:Program. TestLists.mod
:Contents. test module for Lists [bne]
:Author. Nicolas Benezan [bne]
:Address. Postwiesenstr. 2, D7000 Stuttgart 60
:Phone. 711/333679
:Copyright. Public Domain
:Language. Modula-2
:Translator. M2Amiga A+L V3.2d
:Imports. Lists2.0, MemSystem1.2 [bne]
:History. V1.0b [bne] 11.May.1989
**********************************************************************)
MODULE TestLists;
FROM Conversions IMPORT ValToStr;
FROM InOut IMPORT WriteString,WriteInt,WriteLn;
FROM Lists IMPORT List, EntryPtr, ListsAllocProc, ListsDeallocProc,
CreateList, DeleteList, AppendEntryC, InsertEntryC,
DeleteEntry, ReadEntryC, ReplaceEntryC,
LocateEntryAbs, LocateEntryRel, Successor,
Predecessor, FirstEntry, LastEntry, EntriesInList;
FROM MemSystem IMPORT NoCareAllocate, Deallocate;
FROM Str IMPORT Concat;
TYPE
String=ARRAY [0..20] OF CHAR;
VAR
list:List;
entry:EntryPtr;
dummy:BOOLEAN; (* NoCareAllocate() never fails *)
PROCEDURE PrintEntry;
VAR
Data:String;
BEGIN
WriteString(" ");
ReadEntryC(list,entry,Data);
WriteString(Data);
WriteLn;
END PrintEntry;
PROCEDURE PrintList;
BEGIN
WriteString("List has ");
WriteInt(EntriesInList(list),1);
WriteString(" entries:");
WriteLn;
IF EntriesInList(list)#0 THEN
entry:=FirstEntry(list);
REPEAT
PrintEntry;
UNTIL NOT Successor(entry);
END;
WriteLn;
END PrintList;
PROCEDURE InitList;
BEGIN
dummy:=CreateList(list);
WriteString("List created.");
WriteLn;
PrintList;
END InitList;
PROCEDURE AppendTest;
VAR
Num:INTEGER;
Data,NumStr,Text:String;
BEGIN
WriteString("Appending 10 entries...");
WriteLn;
Text:="Entry No. ";
FOR Num:=1 TO 10 DO
ValToStr(Num,FALSE,NumStr,10,1," ",dummy);
Data:=Text;
Concat(Data,NumStr);
AppendEntryC(list,Data);
END;
PrintList;
END AppendTest;
PROCEDURE DiscardList;
BEGIN
DeleteList(list);
WriteString("List deleted.");
WriteLn;
WriteString("End of Test.");
WriteLn;
END DiscardList;
PROCEDURE InsertTest;
VAR
Data:String;
BEGIN
WriteString("Inserting at the head...");
WriteLn;
Data:="Inserted head";
InsertEntryC(list,FirstEntry(list),Data);
WriteString("Inserting in the middle...");
WriteLn;
Data:="Inserted middle";
InsertEntryC(list,LocateEntryAbs(list,6),Data);
PrintList;
END InsertTest;
PROCEDURE ReplaceTest;
VAR
Data:String;
BEGIN
WriteString("Replacing an Entry...");
WriteLn;
Data:="Overwritten entry";
ReplaceEntryC(list,LocateEntryAbs(list,6),Data);
PrintList;
END ReplaceTest;
PROCEDURE DeleteTest;
BEGIN
WriteString("Deleting previously added entries...");
WriteLn;
DeleteEntry(list,FirstEntry(list));
DeleteEntry(list,LocateEntryAbs(list,5));
PrintList;
END DeleteTest;
PROCEDURE LocateTest;
BEGIN
WriteString("Scanning backward...");
WriteLn;
entry:=LastEntry(list);
REPEAT
PrintEntry;
UNTIL NOT Predecessor(entry);
WriteString("Positioning on 5th Entry");
WriteLn;
entry:=LocateEntryAbs(list,4);
PrintEntry;
WriteString("browsing 3 backward");
WriteLn;
dummy:=LocateEntryRel(list,entry,-3);
PrintEntry;
WriteString("browsing 7 forward");
WriteLn;
dummy:=LocateEntryRel(list,entry,7);
PrintEntry;
WriteString("LocateEntry() beyond tail (error)");
WriteLn;
IF LocateEntryRel(list,entry,2) THEN
WriteString("WARNING: No error detected!");
ELSE
WriteString("Ok. Error reported correctly");
END;
WriteLn;
END LocateTest;
BEGIN
ListsAllocProc:=NoCareAllocate;
ListsDeallocProc:=Deallocate;
InitList;
AppendTest;
InsertTest;
ReplaceTest;
DeleteTest;
LocateTest;
DiscardList;
END TestLists.